package com.base.controller;

import com.base.comm.CommContent;
import com.base.po.voip.CompanyCarousel;
import com.base.service.CompanyCarouselService;
import com.base.service.LogsService;
import com.base.utils.IP;
import com.base.utils.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 添加方案轮播
 */
@Controller
@RequestMapping("/admin")
public class add_CompanyCarousel {

	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private CompanyCarouselService companyCarouselService; // 分类信息

	// 添加分类
	@RequestMapping(value = "/toAddCompanyCarousel", method = RequestMethod.POST)
	public @ResponseBody int toAddCompanyCarousel(HttpServletRequest request, CompanyCarousel companyCarousel){
		String userid = (String) request.getSession().getAttribute("adminUserId"); // 登录的用户ID
		if (userid == null) return -1; // 未登录
		companyCarousel.setId(Produce.getUUID());
		companyCarousel.setCreatetime(Produce.getNowDate()); // 创建时间
		companyCarousel.setParentid(userid); // 代理商ID
		companyCarousel.setDatastatus((byte) 1); // 状态可用
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "方案轮播信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return companyCarouselService.insertSelective(companyCarousel); // 添加
	}
}
